package com.zc.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.zc.domain.Item;

@Repository
public interface IElecDao {
	@Select("SELECT TimeStamp,DD FROM ${tableName} ORDER BY TimeStamp DESC LIMIT 24;")
	@Results({
		@Result(column = "TimeStamp",property = "timeStamp"),
		@Result(column = "DD",property = "data")
	})
	List<Item> getElec(@Param("tableName") String tableName);
	
	@Select("SELECT TimeStamp,DD FROM ${tableName} WHERE TimeStamp>'${date}' ORDER BY TimeStamp DESC;")
	@Results({
		@Result(column = "TimeStamp",property = "timeStamp"),
		@Result(column = "DD",property = "data")
	})
	List<Item> getTodayElec(@Param("tableName") String tableName,@Param("date") String date);
	
	@Select("SELECT TimeStamp,DD FROM ${tableName} WHERE TimeStamp>'${beginDate}' AND TimeStamp<'${endDate}' ORDER BY TimeStamp DESC;")
	@Results({
		@Result(column = "TimeStamp",property = "timeStamp"),
		@Result(column = "DD",property = "data")
	})
	List<Item> getMonthElec(@Param("tableName") String tableName,@Param("beginDate") String beginDate,@Param("endDate") String endDate);
	
	@Select("SELECT DATE_FORMAT(TimeStamp, '%Y-%m') as t,SUM(DD) as d FROM ${tableName} WHERE TimeStamp>'${date}' GROUP BY DATE_FORMAT(TimeStamp, '%Y-%m') ORDER BY t DESC;")
	@Results({
		@Result(column = "t",property = "timeStamp"),
		@Result(column = "d",property = "data")
	})
	List<Item> getYearElec(@Param("tableName") String tableName,@Param("date") String date);
	
	@Select("SELECT TimeStamp,DD FROM ${tableName} WHERE TimeStamp>'${beginDate}' AND TimeStamp<'${endDate}';")
	@Results({
		@Result(column = "TimeStamp",property = "timeStamp"),
		@Result(column = "DD",property = "data")
	})
	List<Item> select(@Param("tableName") String tableName,@Param("beginDate") String beginDate,@Param("endDate") String endDate);
	
	@Select("SELECT DATE_FORMAT(TimeStamp, '%Y-%m') as t,SUM(DD) as d FROM ${tableName} WHERE TimeStamp>'${beginDate}' AND TimeStamp<'${endDate}' GROUP BY DATE_FORMAT(TimeStamp, '%Y-%m') ORDER BY t DESC;")
	@Results({
		@Result(column = "t",property = "timeStamp"),
		@Result(column = "d",property = "data")
	})
	List<Item> yearSelect(@Param("tableName") String tableName,@Param("beginDate") String beginDate,@Param("endDate") String endDate);
}
